<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24" class="card-box">
        <el-card>
          <el-form >
            <tbody>
            <td style="width: 80px"><span>选择时间:</span></td>
            <td style="width: 250px"><el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker></td>
            <td> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button></td>
            </tbody>
          </el-form>
        </el-card>
      </el-col>
      <el-col :span="24" class="card-box">
        <el-card>
            <table cellspacing="0" style="width: 15%">
              <tbody>
              <span >合计收入:￥</span>
              </tbody>
            </table>
        </el-card>
      </el-col>
          <el-col  class="card-box">
            <el-card>
            <table cellspacing="0">
              <tbody>
              <tr align="left">
                <td style="width: 130px"><span class="cell" >收支概况:</span></td>
                <td style="width: 150px"><span class="cell" v-if="cache.info">总收入:￥</span></td>
                <td><div class="cell" v-if="cache.info">总退费:￥</div></td>
              </tr>
              </tbody>
            </table>
            </el-card>
          </el-col>
      <el-col :span="24" class="card-box">
        <el-card>
            <table cellspacing="0">
              <tbody>
              <td style="width: 130px"><div class="cell">收入来源:</div></td>
              <td style="width: 150px"><div class="cell" v-if="cache.info">现金支付:￥</div></td>
              <td style="width: 180px"><div class="cell" v-if="cache.info">支付宝支付:￥</div></td>
              <td style="width: 170px"><div class="cell" v-if="cache.info">现金退费:￥</div></td>
              <td ><div class="cell" v-if="cache.info">支付宝支付:￥</div></td>
              </tbody>
            </table>
        </el-card>
      </el-col>

      <el-col :span="24" class="card-box">
        <el-card>
          <div class="el-table el-table--enable-row-hover el-table--mini">
            <div ref="commandstats" style="height: 420px" />
          </div>
          <div class="el-table el-table--enable-row-hover el-table--mini">
            <div ref="usedmemory" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getCache } from "@/api/monitor/cache";
import echarts from "echarts";

export default {
  name: "Server",
  data() {
    return {
      // 加载层信息
      loading: [],
      // 统计命令信息
      commandstats: null,
      // 使用内存
      usedmemory: null,
      // cache信息
      cache: [],
        //日期范围
        dateRange: [],
        //总收入
        totalIncome:'0'
    };
  },
  created() {
    this.getList();
    this.openLoading();
  },
  methods: {
    /** 查缓存询信息 */
    getList() {
        sum().then((response) => {
        this.totalIncome = response.data;

        this.commandstats = echarts.init(this.$refs.commandstats, "macarons");
        this.commandstats.setOption({
          tooltip: {
            trigger: "item",
            formatter: "{a} <br/>{b} : {c} ({d}%)",
          },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
          series: [
            {
              name: "命令",
              type: "pie",
              roseType: "radius",
              radius: [15, 95],
              center: ["50%", "38%"],
              data: response.data.commandStats,
              animationEasing: "cubicInOut",
              animationDuration: 1000,
            },
          ],
        });
        this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
        this.usedmemory.setOption({
          tooltip: {
            formatter: "{b} <br/>{a} : " + this.cache.info.used_memory_human,
          },
          series: [
            {
              name: "峰值",
              type: "gauge",
              min: 0,
              max: 1000,
              detail: {
                formatter: this.cache.info.used_memory_human,
              },
              data: [
                {
                  value: parseFloat(this.cache.info.used_memory_human),
                  name: "内存消耗",
                },
              ],
            },
          ],
        });
      });
    },
    // 打开加载层
    openLoading() {
      this.loading = this.$loading({
        lock: true,
        text: "拼命读取中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
  },
};

</script>
